package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Description NursingPlanController
 * @Author pengtao
 * @Date 2025-05-11  15:42
 */
@RequestMapping("/nursing/plan")
@RestController
@Api(tags ="护理计划")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    //增加
    @PostMapping
    public ResponseResult save(@RequestBody NursingPlanVo nursingPlanVo) {
        nursingPlanService.save(nursingPlanVo);
        return ResponseResult.success();
    }
    //id查寻
    @GetMapping("{id}")
    public ResponseResult getById(@PathVariable("id") Long id) {
        NursingPlanDto nursingPlanDto = nursingPlanService.getById(id);
        return success(nursingPlanDto);
    }
    //查询所有
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAll(){
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAll();
        return success(nursingPlanVos);
    }
    //删除
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") Long id) {
        nursingPlanService.delete(id);
        return success();
    }
    //修改
    @PutMapping
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.update(nursingPlanDto);
        return success();
    }
    //分页查询
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanDto>> search(
            @ApiParam(value = "名称")
            @RequestParam(value = "planName" ,required = false )String planName,
            @ApiParam(value = "状态：0-禁用 , 1-启用 ")
            @RequestParam(value = "status" ,required = false)Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
            ){
        PageResponse<NursingPlanDto> nursingPlanPageInfo = nursingPlanService.search(planName, status, pageNum, pageSize);
        return success(nursingPlanPageInfo);

    }


}
